package cn.com.fssg.platform.base.handler.impl.ryxwdj;

import cn.com.fssg.platform.base.handler.InterfaceHandler;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @Description: 人员行为登记记录状态更新或者删除接口
 */
@Component
public class RyxwdjUpdateOrDelCtl implements InterfaceHandler {

//    private NamedParameterJdbcTemplate jdbcTemplate = BizUtil.cur().tenantMainJdbcTemplate();

    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;

    @Override
    public Object run(HttpServletRequest request, JSONObject jsonObject) throws Exception {
        String ids = jsonObject.get("ids").toString();
        List<String> idList = Arrays.asList(ids.split(","));
        String type = jsonObject.get("type").toString();
        String operate = jsonObject.get("operate").toString();
        HashMap<String, Object> params = new HashMap<>();
        params.put("ids", idList);
        String sql = "";
        if ("del".equals(operate)) {
            sql = "DELETE FROM bs_qyxyxwdj where id in (:ids) and zt in ('已退回','未确认')";
            if (!type.equals("qy")) {
                // 不是企业行为登记就是关键人员评价
                sql = "DELETE FROM bs_ryxyxwdj where id in (:ids) and zt in ('已退回','未确认')";
            }
        } else {
            sql = "UPDATE bs_qyxyxwdj SET zt='已确认' where id in (:ids)";
            if (!type.equals("qy")) {
                // 不是企业行为登记就是关键人员评价
                sql = "UPDATE bs_ryxyxwdj SET zt='已确认' where id in (:ids)";
            }
        }
        jdbcTemplate.update(sql, params);
        return null;
    }

}
